﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntropiaMiningMap
{
    /// <summary>
    /// Contains the map dimensions, current level of zoom, and any materials
    /// </summary>
    class Map
    {
        /// <summary>
        /// Width of the map
        /// </summary>
        private int width;

        /// <summary>
        /// Height of the map
        /// </summary>
        private int height;

        /// <summary>
        /// Half-width of the map
        /// </summary>
        private float halfWidth;

        /// <summary>
        /// Half-height of the map
        /// </summary>
        private float halfHeight;

        /// <summary>
        /// Zoom value of the map
        /// </summary>
        private float zoom;

        /// <summary>
        /// Minimum zoom value
        /// </summary>
        private float minZoom;

        /// <summary>
        /// Maximum zoom value
        /// </summary>
        private float maxZoom;

        /// <summary>
        /// Point representing the coordinates at the center of the viewable map
        /// </summary>
        private Point center;

        /// <summary>
        /// List of all materials on the map
        /// </summary>
        private Dictionary<String, Material> materials;

        /// <summary>
        /// List of all materials to draw on the map
        /// </summary>
        private Dictionary<String, Material> drawList;

        /// <summary>
        /// Default constructor
        /// </summary>
        public Map()
        {
            width = 0;
            height = 0;
            center = new Point(0.0f, 0.0f);
            zoom = 1.0f;
            minZoom = 1.0f;
            maxZoom = 100.0f;
            materials = new Dictionary<String, Material>();
            drawList = new Dictionary<String, Material>();

            // Load map contents if already exists
            LoadMap();
        }

        /// <summary>
        /// Load a map
        /// </summary>
        private void LoadMap()
        {
            width = 100000;
            height = 100000;

            halfWidth = (float)width / 2.0f;
            halfHeight = (float)height / 2.0f;

            center = new Point(50000.0f, 50000.0f);
        }

        /// <summary>
        /// Add a new material to the map
        /// </summary>
        /// <param name="name"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void AddNewMaterial(String name, int x, int y)
        {
            materials.Add(name, new Material(name, x, y));
        }

        /// <summary>
        /// Load a pre-existing material into the map
        /// </summary>
        /// <param name="m">Material to attach</param>
        public void LoadMaterial(Material m)
        {
            materials.Add(m.Name, m);
        }

        /// <summary>
        /// Add a material to the draw list
        /// </summary>
        /// <param name="name"></param>
        public void AddToDrawList(String name)
        {
            drawList.Add(name, materials[name]);
        }

        // Remove a material from the draw list
        public void RemoveFromDrawList(String name)
        {
            drawList.Remove(name);
        }

        /// <summary>
        /// Zoom into the map
        /// </summary>
        public void ZoomIn()
        {
            // As long as we are not more zoomed in than the max
            if (zoom < maxZoom)
            {
                // Zoom in by 10% of the original size
                zoom += 0.1f;
            }
        }

        /// <summary>
        /// Zoom out of the map
        /// </summary>
        public void ZoomOut()
        {
            // As long as we are not zoomed out more than the min
            if (zoom > minZoom)
            {
                zoom -= 0.1f;
            }
        }

        // Properties
        //*****************************************************************************************

        /// <summary>
        /// Accessor for width
        /// </summary>
        public int Width
        {
            get { return width; }
        }

        /// <summary>
        /// Accessor for height
        /// </summary>
        public int Height
        {
            get { return height; }
        }

        /// <summary>
        /// Accessor for half-width
        /// </summary>
        public float HalfWidth
        {
            get { return halfWidth; }
        }

        // Accessor for half-height
        public float HalfHeight
        {
            get { return halfHeight; }
        }

        /// <summary>
        /// Accessor and mutator for zoom
        /// </summary>
        public float Zoom
        {
            get { return zoom; }
            set { zoom = value; }
        }

        /// <summary>
        /// Accessor and mutator for center
        /// </summary>
        public Point Center
        {
            get { return center; }
            set { center = value; }
        }

        /// <summary>
        /// Accessor for materials
        /// </summary>
        public Dictionary<String, Material> Materials
        {
            get { return materials; }
        }

        /// <summary>
        /// Accessor for the draw list
        /// </summary>
        public Dictionary<String, Material> DrawList
        {
            get { return drawList; }
        }

    }
}
